import { createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'search',
    component: () => import('../components/SearchPage.vue')
  },
  {
    path: '/log/:id',
    name: 'search2',
    component: () => import('../components/SearchPage.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../components/LoginPage.vue')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../components/registerPage.vue')
  },
  {
    path: '/log/:id/lawyer/:character',
    name: 'lawyer',
    component: () => import(/* webpackChunkName: "about" */ '../components/lawyerPage.vue')
  },
  {
    path: '/log/:id/inform/:character/person/:pid',
    name: 'inform',
    component: () => import(/* webpackChunkName: "about" */ '../components/InformPage.vue')
  },
  {
    path: '/log/:id/user',
    name: 'user',
    component: () => import(/* webpackChunkName: "about" */ '../components/UserPage.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export let previousPageUrl = ''; // 默认值为根路径

router.beforeEach((to, from, next) => {
  // 在导航守卫中更新前一个页面的路径
  previousPageUrl = decodeURIComponent(from.fullPath)
  next();
})

export default router
